package com.bxd.baodan.fragment;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bxd.baodan.R;
import com.bxd.baodan.item.FamDesignBean;
import com.bxd.baodan.util.StringUtil;
import com.bxd.baodan.widget.IosSheetDialog;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */

public class JobFragment extends BaseStepFragment {

    private TextView job;
    private TextView jobDesc;
    private TextView yearIncomeDesc;
    private EditText yearIncome;
    private LinearLayout job_ly;

    public List<FamDesignBean.ValueBean> jobList = new ArrayList<>();

    public  String[] strings;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.step_2_job, null);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);


        title.setText(roleText +"的职业和收入" );
        title1.setText(roleText +"的职业" );
        title2.setText(roleText +"的年收入" );


        job = (TextView) view.findViewById(R.id.job);
        jobDesc = (TextView) view.findViewById(R.id.job_desc);
        yearIncomeDesc = (TextView) view.findViewById(R.id.year_income_desc);
        yearIncome = (EditText) getView().findViewById(R.id.year_income);
        job_ly = (LinearLayout) view.findViewById(R.id.job_ly);



//开始时是不会有career,所以数据的初始化放在onclick之后
        if(!StringUtil.isEmpty(getDesignStep().career)){
           String a = getDesignStep().career;
           int b = Integer.parseInt(a);
           job.setText(jobList.get(b-1).name);

       }
       if(!StringUtil.isEmpty(getDesignStep().personal_annual_income)){
           yearIncome.setText(getDesignStep().personal_annual_income);

       }



        job_ly.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //数据
                jobList = getBean().data.condition.career.value;
                strings = new String[jobList.size()];
                for (int i = 0; i < jobList.size(); i++) {
                    strings[i] = jobList.get(i).name;
                }


                IosSheetDialog dialog = new IosSheetDialog(getActivity()).builder().setCancelable(false).setCanceledOnTouchOutside(true);
                dialog.setSheetItems(strings, new IosSheetDialog.DialogItemListener() {
                    @Override
                    public void onClick(int position) {
                        job.setText(strings[position]);
                        getDesignStep().career = jobList.get(position).id;

                    }
                });
                dialog.show();
            }
        });

        yearIncome.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
              getDesignStep().personal_annual_income = yearIncome.getText().toString();
            }
        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }
}
